/*
*
* 用于简单拾取的类pick.js
*
* */

define(function(){
    var scope;
    var ray = function (modelArr,camera) {
        if(modelArr===undefined)return;
        scope = this;
        this.arr = modelArr;
        this.cam = camera;
        this.pickEnable = true;
    };
    
    Object.defineProperties( ray.prototype, {
        
        "model": {
            
            get: function () {
                
                return this.arr;
                
            },
            
            set: function ( value ) {
                
                this.arr = value;
                
            }
            
        },
        
        "camera": {
            
            get: function () {
                
                return this.cam;
                
            },
            
            set: function ( camera ) {
                
                this.cam = camera;
                
            }
            
        }
        
    } );
    
    Object.assign(ray.prototype,{
        pick:function (event,callback) {
            
            if(scope.pickEnable === false)return;
            
            if (event) event.preventDefault();
            var raycaster = new THREE.Raycaster();
            var mouse = new THREE.Vector2();
    
            mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
            mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
    
            raycaster.setFromCamera(mouse, scope.cam);
    
            var feedback = raycaster.intersectObjects(scope.arr);
            callback && callback(feedback);
            
            return feedback
        },
        
    
    });
    
    return ray;
});